package com.yh.homestay.controller;

import com.yh.homestay.common.CapitalGoodsRustlt;
import com.yh.homestay.common.ResultMessage;
import com.yh.homestay.pojo.CapitalGoods;
import com.yh.homestay.service.impl.CapitalGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * 物资管理
 */
@Controller
public class CapitalGoodsController {
    @Autowired
    private CapitalGoodsService capitalGoodsService;
    //展示物资信息
  /*  @RequestMapping("/materiel/list")
    @ResponseBody
    public ResultMessage findAllMatriel(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit) {
        List<CapitalGoods> list = capitalGoodsService.findAllCapitalGoods(page,limit);
        ResultMessage res=new ResultMessage(0," ",list.size(),list);
        return res;
    }*/
/*    @RequestMapping(value = "/materiel/list")
    @ResponseBody
    public ResultMessage findAllMatriel(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit,String start,String end,String goodsName) {

        System.out.println(">>>>>>>>>>>>"+start+">>>>>>>>>>>>"+end+">>>>>>>>>>>>>>>>>>>>>"+goodsName);
        return capitalGoodsService.findAllCapitalGoods(page,limit);
    }*/
    @RequestMapping(value = "/materiel/list")
    @ResponseBody
    public ResultMessage findAllMatriel( Integer page, Integer limit, String start, String end, String goodsName) {
        return capitalGoodsService.findAllCapitalGoods(page,limit,start,end,goodsName);
    }

    //添加物资
    @RequestMapping("/materiel/addMateriel")
    @ResponseBody
    public CapitalGoodsRustlt addMateriel(CapitalGoods good) {
       //补全对象属性
        good.setGoodsType(1);
        good.setGoodsArea("仓库");
        return capitalGoodsService.addCapitalGood(good);
    }
    //删除物资
    @RequestMapping("/materiel/deleteSingleMateriel")
    @ResponseBody
    public CapitalGoodsRustlt delSingle(String goodsNumber) {
        return capitalGoodsService.delSingleCapitalGood(goodsNumber);
    }
    //批量删除物资
    @RequestMapping(value="/materiel/deleteMateriel")
    @ResponseBody
    public CapitalGoodsRustlt del( String nums) {

        return capitalGoodsService.delCapitalGood(nums);

    }
    //修改物资数据回显
    @RequestMapping("/materiel/toMaterieledit/{num}")
    @ResponseBody
    public CapitalGoodsRustlt seleteCapitalSingle(@PathVariable String num) {
        return capitalGoodsService.seleteCapitalSingle(num);

    }
    //修改物资信息
    @RequestMapping("/materiel/updataMateriel")
    @ResponseBody
    public CapitalGoodsRustlt updateMateriel( CapitalGoods good) {
        return capitalGoodsService.updataMaterielSingle(good);
    }


}
